<!DOCTYPE HTML>

<html lang="en">
<head>

<title>WithSecurityContext (spring-security-docs 5.6.3 API)</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<link rel="stylesheet" type="text/css" href="../../../../../../stylesheet.css" title="Style">
<link rel="stylesheet" type="text/css" href="../../../../../../jquery/jquery-ui.css" title="Style">
<script type="text/javascript" src="../../../../../../script.js"></script>
<script type="text/javascript" src="../../../../../../jquery/jszip/dist/jszip.min.js"></script>
<script type="text/javascript" src="../../../../../../jquery/jszip-utils/dist/jszip-utils.min.js"></script>
<!--[if IE]>
<script type="text/javascript" src="../../../../../../jquery/jszip-utils/dist/jszip-utils-ie.min.js"></script>
<![endif]-->
<script type="text/javascript" src="../../../../../../jquery/jquery-3.5.1.js"></script>
<script type="text/javascript" src="../../../../../../jquery/jquery-ui.js"></script>
</head>
<body>
<script type="text/javascript"><!--
    try {
        if (location.href.indexOf('is-external=true') == -1) {
            parent.document.title="WithSecurityContext (spring-security-docs 5.6.3 API)";
        }
    }
    catch(err) {
    }
//-->
var pathtoroot = "../../../../../../";
var useModuleDirectories = true;
loadScripts(document, 'script');</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
<header role="banner">
<nav role="navigation">
<div class="fixedNav">

<div class="topNav"><a id="navbar.top">

</a>
<div class="skipNav"><a href="WithSecurityContext.html#skip.navbar.top" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.top.firstrow">

</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_top">
<li><a href="../../../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<ul class="navListSearch">
<li><label for="search">SEARCH:</label>
<input type="text" id="search" value="search" disabled="disabled">
<input type="reset" id="reset" value="reset" disabled="disabled">
</li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_top");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="WithSecurityContext.html#annotation.type.required.element.summary">Required</a>&nbsp;|&nbsp;</li>
<li><a href="WithSecurityContext.html#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="WithSecurityContext.html#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a id="skip.navbar.top">

</a></div>

</div>
<div class="navPadding">&nbsp;</div>
<script type="text/javascript"><!--
$('.navPadding').css('padding-top', $('.fixedNav').css("height"));
//-->
</script>
</nav>
</header>

<main role="main">
<div class="header">
<div class="subTitle"><span class="packageLabelInType">Package</span>&nbsp;<a href="package-summary.html">org.springframework.security.test.context.support</a></div>
<h2 title="Annotation Type WithSecurityContext" class="title">Annotation Type WithSecurityContext</h2>
</div>
<div class="contentContainer">
<div class="description">
<ul class="blockList">
<li class="blockList">
<hr>
<pre>@Target(ANNOTATION_TYPE)
@Retention(RUNTIME)
@Inherited
@Documented
public @interface <span class="memberNameLabel">WithSecurityContext</span></pre>
<div class="block"><p>
An annotation to determine what <a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a> to use. The <a href="WithSecurityContext.html#factory()"><code>factory()</code></a>
attribute must be provided with an instance of
<code>WithUserDetailsSecurityContextFactory</code>.
</p>
<p>
Typically this annotation will be used as an meta-annotation as done with
<a href="WithMockUser.html" title="annotation in org.springframework.security.test.context.support"><code>WithMockUser</code></a> and <a href="WithUserDetails.html" title="annotation in org.springframework.security.test.context.support"><code>WithUserDetails</code></a>.
</p>
<p>
If you would like to create your own implementation of
<a href="WithSecurityContextFactory.html" title="interface in org.springframework.security.test.context.support"><code>WithSecurityContextFactory</code></a> you can do so by implementing the interface. You can
also use <code>Autowired</code> and other Spring semantics on the
<a href="WithSecurityContextFactory.html" title="interface in org.springframework.security.test.context.support"><code>WithSecurityContextFactory</code></a> implementation.
</p></div>
<dl>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>4.0</dd>
</dl>
</li>
</ul>
</div>
<div class="summary">
<ul class="blockList">
<li class="blockList">

<section role="region">
<ul class="blockList">
<li class="blockList"><a id="annotation.type.required.element.summary">

</a>
<h3>Required Element Summary</h3>
<table class="memberSummary">
<caption><span>Required Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colSecond" scope="col">Required Element</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code>java.lang.Class&lt;? extends <a href="WithSecurityContextFactory.html" title="interface in org.springframework.security.test.context.support">WithSecurityContextFactory</a>&lt;? extends java.lang.annotation.Annotation&gt;&gt;</code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="WithSecurityContext.html#factory()">factory</a></span></code></th>
<td class="colLast">
<div class="block">The <code>WithUserDetailsSecurityContextFactory</code> to use to create the
<a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a>.</div>
</td>
</tr>
</table>
</li>
</ul>
</section>

<section role="region">
<ul class="blockList">
<li class="blockList"><a id="annotation.type.optional.element.summary">

</a>
<h3>Optional Element Summary</h3>
<table class="memberSummary">
<caption><span>Optional Elements</span><span class="tabEnd">&nbsp;</span></caption>
<tr>
<th class="colFirst" scope="col">Modifier and Type</th>
<th class="colSecond" scope="col">Optional Element</th>
<th class="colLast" scope="col">Description</th>
</tr>
<tr class="altColor">
<td class="colFirst"><code><a href="TestExecutionEvent.html" title="enum in org.springframework.security.test.context.support">TestExecutionEvent</a></code></td>
<th class="colSecond" scope="row"><code><span class="memberNameLink"><a href="WithSecurityContext.html#setupBefore()">setupBefore</a></span></code></th>
<td class="colLast">
<div class="block">Determines when the <a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a> is setup.</div>
</td>
</tr>
</table>
</li>
</ul>
</section>
</li>
</ul>
</div>
<div class="details">
<ul class="blockList">
<li class="blockList">

<section role="region">
<ul class="blockList">
<li class="blockList"><a id="annotation.type.element.detail">

</a>
<h3>Element Detail</h3>
<a id="factory()">

</a>
<ul class="blockListLast">
<li class="blockList">
<h4>factory</h4>
<pre>java.lang.Class&lt;? extends <a href="WithSecurityContextFactory.html" title="interface in org.springframework.security.test.context.support">WithSecurityContextFactory</a>&lt;? extends java.lang.annotation.Annotation&gt;&gt;&nbsp;factory</pre>
<div class="block">The <code>WithUserDetailsSecurityContextFactory</code> to use to create the
<a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a>. It can contain <code>Autowired</code> and other Spring
annotations.</div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
</dl>
</li>
</ul>
</li>
</ul>
</section>

<section role="region">
<ul class="blockList">
<li class="blockList"><a id="setupBefore()">

</a>
<ul class="blockListLast">
<li class="blockList">
<h4>setupBefore</h4>
<pre><a href="TestExecutionEvent.html" title="enum in org.springframework.security.test.context.support">TestExecutionEvent</a>&nbsp;setupBefore</pre>
<div class="block">Determines when the <a href="../../../core/context/SecurityContext.html" title="interface in org.springframework.security.core.context"><code>SecurityContext</code></a> is setup. The default is before
<a href="TestExecutionEvent.html#TEST_METHOD"><code>TestExecutionEvent.TEST_METHOD</code></a> which occurs during
<code>TestExecutionListener.beforeTestMethod(TestContext)</code></div>
<dl>
<dt><span class="returnLabel">Returns:</span></dt>
<dd>the <a href="TestExecutionEvent.html" title="enum in org.springframework.security.test.context.support"><code>TestExecutionEvent</code></a> to initialize before</dd>
<dt><span class="simpleTagLabel">Since:</span></dt>
<dd>5.1</dd>
</dl>
<dl>
<dt>Default:</dt>
<dd>org.springframework.security.test.context.support.TestExecutionEvent.TEST_METHOD</dd>
</dl>
</li>
</ul>
</li>
</ul>
</section>
</li>
</ul>
</div>
</div>
</main>

<footer role="contentinfo">
<nav role="navigation">

<div class="bottomNav"><a id="navbar.bottom">

</a>
<div class="skipNav"><a href="WithSecurityContext.html#skip.navbar.bottom" title="Skip navigation links">Skip navigation links</a></div>
<a id="navbar.bottom.firstrow">

</a>
<ul class="navList" title="Navigation">
<li><a href="../../../../../../index.html">Overview</a></li>
<li><a href="package-summary.html">Package</a></li>
<li class="navBarCell1Rev">Class</li>
<li><a href="package-tree.html">Tree</a></li>
<li><a href="../../../../../../deprecated-list.html">Deprecated</a></li>
<li><a href="../../../../../../index-all.html">Index</a></li>
<li><a href="../../../../../../help-doc.html">Help</a></li>
</ul>
</div>
<div class="subNav">
<ul class="navList" id="allclasses_navbar_bottom">
<li><a href="../../../../../../allclasses.html">All&nbsp;Classes</a></li>
</ul>
<div>
<script type="text/javascript"><!--
  allClassesLink = document.getElementById("allclasses_navbar_bottom");
  if(window==top) {
    allClassesLink.style.display = "block";
  }
  else {
    allClassesLink.style.display = "none";
  }
  //-->
</script>
<noscript>
<div>JavaScript is disabled on your browser.</div>
</noscript>
</div>
<div>
<ul class="subNavList">
<li>Summary:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="WithSecurityContext.html#annotation.type.required.element.summary">Required</a>&nbsp;|&nbsp;</li>
<li><a href="WithSecurityContext.html#annotation.type.optional.element.summary">Optional</a></li>
</ul>
<ul class="subNavList">
<li>Detail:&nbsp;</li>
<li>Field&nbsp;|&nbsp;</li>
<li><a href="WithSecurityContext.html#annotation.type.element.detail">Element</a></li>
</ul>
</div>
<a id="skip.navbar.bottom">

</a></div>

</nav>
</footer>
<script>if (window.parent == window) {(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o), m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)})(window,document,'script','//www.google-analytics.com/analytics.js','ga');ga('create', 'UA-2728886-23', 'auto', {'siteSpeedSampleRate': 100});ga('send', 'pageview');}</script><script defer src="https://static.cloudflareinsights.com/beacon.min.js/v652eace1692a40cfa3763df669d7439c1639079717194" integrity="sha512-Gi7xpJR8tSkrpF7aordPZQlW2DLtzUlZcumS8dMQjwDHEnw9I7ZLyiOj/6tZStRBGtGgN6ceN6cMH8z7etPGlw==" data-cf-beacon='{"rayId":"7040f6c6090a97cf","token":"bffcb8a918ae4755926f76178bfbd26b","version":"2021.12.0","si":100}' crossorigin="anonymous"></script>
</body>
</html>
